//
//  VisitorTableViewController.swift
//  XinLangWeiBo
//
//  Created by lei on 17/2/10.
//  Copyright © 2017年 lei. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    /// 用户登录标记
    private var userLogon = false
    
    /// 访客视图
    var visitorView: VisitorView?
    
    
    override func loadView() {
        
        // 根据用户登录情况, 决定显示的跟视图
        userLogon ? super.loadView() : setupVisitorView()
        
    }
    
    /// 设置访客视图
    private func setupVisitorView() {
        
        // 替换跟视图
        visitorView = VisitorView()
    
        view = visitorView

        //添加监听方法
        visitorView?.registerButton.addTarget(self, action: #selector(VisitorTableViewController.visitorViewDidRegister), forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: #selector(VisitorTableViewController.visitorViewDidLogin), forControlEvents: UIControlEvents.TouchUpInside)
        
        // 设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(VisitorTableViewController.visitorViewDidRegister))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: #selector(VisitorTableViewController.visitorViewDidLogin))
        
    }

}

// MARK: - 访客视图监听方法
extension VisitorTableViewController {
    
    func visitorViewDidRegister() {
        print("注册")
    }
    
    func visitorViewDidLogin() {
        print("登录")
    }
    
}


